/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file    stm32f1xx_it.c
  * @brief   Interrupt Service Routines.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f1xx_it.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */

/* USER CODE END TD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/* External variables --------------------------------------------------------*/

/* USER CODE BEGIN EV */

/* USER CODE END EV */

/******************************************************************************/
/*           Cortex-M3 Processor Interruption and Exception Handlers          */
/******************************************************************************/
/**
  * @brief This function handles Non maskable interrupt.
  */
void NMI_Handler(void)
{
  /* USER CODE BEGIN NonMaskableInt_IRQn 0 */

  /* USER CODE END NonMaskableInt_IRQn 0 */
  /* USER CODE BEGIN NonMaskableInt_IRQn 1 */
  while (1)
  {
  }
  /* USER CODE END NonMaskableInt_IRQn 1 */
}

/**
  * @brief This function handles Hard fault interrupt.
  */
void HardFault_Handler(void)
{
  /* USER CODE BEGIN HardFault_IRQn 0 */

  /* USER CODE END HardFault_IRQn 0 */
  while (1)
  {
    /* USER CODE BEGIN W1_HardFault_IRQn 0 */
    /* USER CODE END W1_HardFault_IRQn 0 */
  }
}

/**
  * @brief This function handles Memory management fault.
  */
void MemManage_Handler(void)
{
  /* USER CODE BEGIN MemoryManagement_IRQn 0 */

  /* USER CODE END MemoryManagement_IRQn 0 */
  while (1)
  {
    /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
    /* USER CODE END W1_MemoryManagement_IRQn 0 */
  }
}

/**
  * @brief This function handles Prefetch fault, memory access fault.
  */
void BusFault_Handler(void)
{
  /* USER CODE BEGIN BusFault_IRQn 0 */

  /* USER CODE END BusFault_IRQn 0 */
  while (1)
  {
    /* USER CODE BEGIN W1_BusFault_IRQn 0 */
    /* USER CODE END W1_BusFault_IRQn 0 */
  }
}

/**
  * @brief This function handles Undefined instruction or illegal state.
  */
void UsageFault_Handler(void)
{
  /* USER CODE BEGIN UsageFault_IRQn 0 */

  /* USER CODE END UsageFault_IRQn 0 */
  while (1)
  {
    /* USER CODE BEGIN W1_UsageFault_IRQn 0 */
    /* USER CODE END W1_UsageFault_IRQn 0 */
  }
}

/**
  * @brief This function handles System service call via SWI instruction.
  */
void SVC_Handler(void)
{
  /* USER CODE BEGIN SVCall_IRQn 0 */

  /* USER CODE END SVCall_IRQn 0 */
  /* USER CODE BEGIN SVCall_IRQn 1 */

  /* USER CODE END SVCall_IRQn 1 */
}

/**
  * @brief This function handles Debug monitor.
  */
void DebugMon_Handler(void)
{
  /* USER CODE BEGIN DebugMonitor_IRQn 0 */

  /* USER CODE END DebugMonitor_IRQn 0 */
  /* USER CODE BEGIN DebugMonitor_IRQn 1 */

  /* USER CODE END DebugMonitor_IRQn 1 */
}

/**
  * @brief This function handles Pendable request for system service.
  */
void PendSV_Handler(void)
{
  /* USER CODE BEGIN PendSV_IRQn 0 */

  /* USER CODE END PendSV_IRQn 0 */
  /* USER CODE BEGIN PendSV_IRQn 1 */

  /* USER CODE END PendSV_IRQn 1 */
}

/**
  * @brief This function handles System tick timer.
  */
void SysTick_Handler(void)
{
  /* USER CODE BEGIN SysTick_IRQn 0 */

  /* USER CODE END SysTick_IRQn 0 */

  /* USER CODE BEGIN SysTick_IRQn 1 */

  /* USER CODE END SysTick_IRQn 1 */
}

/******************************************************************************/
/* STM32F1xx Peripheral Interrupt Handlers                                    */
/* Add here the Interrupt Handlers for the used peripherals.                  */
/* For the available peripheral interrupt handler names,                      */
/* please refer to the startup file (startup_stm32f1xx.s).                    */
/******************************************************************************/

void TIM3_IRQHandler(void)
{
	LL_TIM_ClearFlag_UPDATE(TIM3);
	ToUpdata_timer();
	pulse_count();
	video_pointAB_end_check();
	video_slowly_check();
	delay_FindPoint_endCheck();
	delay_FindPoint_SlowlyCheck();
	delay_move_time_compara();
	delay_slowly_check();
	StopMotion_move_time_compara();
	Stopmotion_FindPoint_endCheck();
	SetABpoint_limite_360_stop();
	Face_mode_pulse_check_stop();
}

/**
  * @brief This function handles TIM4 global interrupt.
  */
void TIM4_IRQHandler(void)
{
	LL_TIM_ClearFlag_UPDATE(TIM4);
	adc_cout();
	time_count();
	video_time_count();
	scan_cycle_count();
	send_interval_count();
	ab_set_time_cout();
	delay_time_countdown();
	active_time_out_countdown();
	ble_shut_time_count();
}

void USART1_IRQHandler(void)
{
	if(LL_USART_IsActiveFlag_RXNE(USART1))
	{
	usart11_read();
	LL_USART_EnableIT_IDLE(USART1);
	}
	
	if(LL_USART_IsActiveFlag_IDLE(USART1))
	{
	 LL_USART_ClearFlag_IDLE(USART1);
	 LL_USART_DisableIT_IDLE(USART1);
	 usart1_receiver();
		// usart11_Recdata_Handling();
	}
	
	
  /* USER CODE END USART2_IRQn 0 */
  /* USER CODE BEGIN USART2_IRQn 1 */

  /* USER CODE END USART2_IRQn 1 */
}

void USART2_IRQHandler(void)
{
	if(LL_USART_IsActiveFlag_RXNE(USART2))
	{
		usart22_read();
		//	usart22_rxne_check();
		LL_USART_EnableIT_IDLE(USART2);
	}
	if(LL_USART_IsActiveFlag_IDLE(USART2))
	{
		LL_USART_ClearFlag_IDLE(USART2); // 
		LL_USART_DisableIT_IDLE(USART2);
		Usart22_Receiver();
		usart22_Recdata_Handling();
	}
  /* USER CODE END USART2_IRQn 0 */
  /* USER CODE BEGIN USART2_IRQn 1 */

  /* USER CODE END USART2_IRQn 1 */
}

void USART3_IRQHandler(void)
{
	if(LL_USART_IsActiveFlag_RXNE(USART3))
	{
		Usart33_readt();
	}
}

void DMA1_Channel3_IRQHandler(void)
{
	LL_DMA_ClearFlag_TC3(DMA1);
	LL_DMA_ClearFlag_GI3(DMA1);
	Usart33_readt();
	//LL_DMA_DisableIT_TC(DMA1, LL_DMA_CHANNEL_4);
}

void DMA1_Channel4_IRQHandler(void)
{
	Dma_SendIRQ_Dispose();
}

void EXTI9_5_IRQHandler(void)
{
	if(LL_EXTI_ReadFlag_0_31(LL_EXTI_LINE_7) == LL_EXTI_LINE_7) // charge 
	{
		LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_7);
		//charge_tag = 1;
	}
	else if(LL_EXTI_ReadFlag_0_31(LL_EXTI_LINE_6) == LL_EXTI_LINE_6) //usb tag
	{
		LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_6);
		usb_voltage_tatus();
		//String_Printf(USART_2,"AA",2);
		charge_tag = 1;
		rtc_wackup = 0;
	}
}

void EXTI15_10_IRQHandler(void)
{
	if(LL_EXTI_ReadFlag_0_31(LL_EXTI_LINE_13) == LL_EXTI_LINE_13) // power key
	{
		LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_13);
		set_press_time();
		rtc_wackup = 0;
	}
	//else if(LL_EXTI_ReadFlag_0_31(LL_EXTI_LINE_11) == LL_EXTI_LINE_11)
	//{
	//	soft_usart_read_byte();
	//	Usart33_read_packet();
	//}
}

void RTC_IRQHandler(void)
{
	LL_RTC_ClearFlag_ALR(RTC);
	LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_17);
	rtc_wackup = 0xff;
	charge_tag = 0;
}

void RTC_Alarm_IRQHandler(void)
{
	LL_RTC_ClearFlag_ALR(RTC);
	LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_17);
	rtc_wackup = 0xff;
	charge_tag = 0;
}

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */
